package com.sc.VenusQueryBeta.ui.fragments.account.changmian;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.dou361.dialogui.DialogUIUtils;
import com.dou361.dialogui.listener.DialogUIDateTimeSaveListener;
import com.dou361.dialogui.widget.DateSelectorWheelView;
import com.example.zhouwei.library.CustomPopWindow;
import com.hengjun.kingstar.sdk.base.BasePresenter;
import com.hengjun.kingstar.sdk.base.fragment.BaseMVPCompatFragment;
import com.hengjun.kingstar.sdk.utils.LogUtil;
import com.hengjun.kingstar.sdk.utils.SpUtils;
import com.hengjun.kingstar.sdk.utils.StringUtils;
import com.hengjun.kingstar.sdk.utils.ToastUtils;
import com.sc.VenusQueryBeta.R;
import com.sc.VenusQueryBeta.adapter.PopAdapter;
import com.sc.VenusQueryBeta.adapter.account.ChangMianAdapter;
import com.sc.VenusQueryBeta.constant.Constants;
import com.sc.VenusQueryBeta.contract.account.changmian.ChangMianContract;
import com.sc.VenusQueryBeta.global.MyApplication;
import com.sc.VenusQueryBeta.model.bean.account.CurrencyListBean;
import com.sc.VenusQueryBeta.model.bean.account.MaxChangemonthBean;
import com.sc.VenusQueryBeta.model.bean.account.changmian.ChangMianPopBean;
import com.sc.VenusQueryBeta.model.bean.account.changmian.ChangmianBean;
import com.sc.VenusQueryBeta.model.bean.login.QueryRegisBean;
import com.sc.VenusQueryBeta.model.bean.login.UsersLoginBean;
import com.sc.VenusQueryBeta.presenter.account.changmian.ChangMianPresenter;

import java.util.Calendar;

import butterknife.BindView;
import butterknife.OnClick;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.header.MaterialHeader;

/**
 * 场面
 */
public class  ChangMianFragment extends BaseMVPCompatFragment<ChangMianContract.ChangMianPresenter> implements ChangMianContract.IChangMianView {

    private static ChangMianFragment fragment;
    @BindView(R.id.ibtn_changmian_back)
    ImageButton ibtnChangmianBack;
    @BindView(R.id.ptr_class)
    PtrClassicFrameLayout ptrClass;
    @BindView(R.id.recyclerview_changmian)
    RecyclerView rvchangmian;
    @BindView(R.id.visible)
    TextView visible;
    @BindView(R.id.total_money)
    TextView totalMoney;
    @BindView(R.id.chooise_company)
    TextView chooiseCompany;
    @BindView(R.id.chooise_time)
    TextView chooiseTime;
    @BindView(R.id.header_ll)
    LinearLayout headerLl;
    @BindView(R.id.vp_fragment)
    FrameLayout vpFragment;
    private View headView;
    private TextView btn_choose_club;
    private TextView btn_choose_time;
    private CustomPopWindow mClubPopWindow;
    private PopAdapter popAdapter;
    private String time1;
    private String time2;
    private QueryRegisBean queryRegisBean;
    private int clientindex;
    private int roomid;
    private TextView total_money;
    private String roomyear;
    private String roommonth;
    private CurrencyListBean mallRoomListBean;//所有廳
    private MaxChangemonthBean mmaxChangemonthBean;
    private boolean isCend = false;
    private RecyclerView clubrecyclerView;
    private UsersLoginBean loginBean;
    private ChangMianAdapter changMianAdapter;
    private View errorView;
    private PopupWindow popupWindow;
    private TextView tv_cash;
    private TextView tv_newM;
    private TextView tv_oldM;
    private TextView tv_wasm;
    private TextView tv_leavesum;
    private TextView tv_baggo;
    private TextView tv_preserve;
    private TextView tv_answerm;
    private TextView tv_nowset;
    private TextView tv_srartsum;
    private View contentView;
    private String currency;
    private boolean isUpdate = false;


    public static ChangMianFragment newInstance(QueryRegisBean queryRegisBean, int clientindex, String currency_type) {
        Bundle args = new Bundle();
        args.putInt(Constants.CLIENTINDEX, clientindex);
        args.putSerializable(Constants.QUERY_SETTING, queryRegisBean);
        args.putString(Constants.CURRENCY_TYPE, currency_type);
        fragment = new ChangMianFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public boolean onBackPressedSupport() {
        pop();
        return true;
    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        if (queryRegisBean != null && !queryRegisBean.getServerSetting().getServerAddress().equals("")) {
            //查询所有厅
//            showProgressDialog("正在加载...");
            mPresenter.queryAllCurrencyList(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort());
        } else {
            ToastUtils.showToast("数据异常");
        }
    }

    /**
     * 初始化头部
     */
//    private void initHeadView() {
//        if (headView == null) {
//            headView = ResourcesUtils.inflate(R.layout.rv_top);
//        }
//        if (errorView == null) {
//            errorView = ResourcesUtils.inflate(R.layout.view_network_error);
//        }
//        errorView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (roommonth.equals("全年")) {
//                    //查询明细
//                    showProgressDialog("正在加载...");
//                    mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
//                            clientindex, "", roomyear, roomid);
//                } else {
//                    //查询明细
//                    showProgressDialog("正在加载...");
//                    mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
//                            clientindex, roommonth, roomyear, roomid);
//                }
//            }
//        });
//        btn_choose_club = headView.findViewById(R.id.chooise_company);
//        total_money = headView.findViewById(R.id.total_money);
//        btn_choose_time = headView.findViewById(R.id.chooise_time);//时间button
//        btn_choose_time.setText(roomyear + "/" + roommonth);//设置日期
//
//
//    }
    private void initClub() {
        View contentView = LayoutInflater.from(mActivity).inflate(R.layout.pop_list, null);
        //处理popWindow 显示内容

        //创建并显示popWindow
        mClubPopWindow = new CustomPopWindow.PopupWindowBuilder(mActivity)
                .setView(contentView)
                .setView(contentView).setOnDissmissListener(new PopupWindow.OnDismissListener() {
                    @Override
                    public void onDismiss() {
                        WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                        lp.alpha = 1f;
                        mActivity.getWindow().setAttributes(lp);
                    }
                })
                .create();
        clubrecyclerView = contentView.findViewById(R.id.recyclerView);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_chang_mian;
    }

    @Override
    public void initUI(View view, @Nullable Bundle savedInstanceState) {
        Calendar c = Calendar.getInstance();//
        roomyear = String.valueOf(c.get(Calendar.YEAR)); // 获取当前年份
        roommonth = String.valueOf(c.get(Calendar.MONTH) + 1);// 获取当前月份
        chooiseTime.setText(roomyear + "/" + roommonth);
        chooiseCompany.setText(currency);
        inputOtherPwdWindow();
        //初始化一个空list的adapter，网络错误时使用，第一次加载到数据时重新初始化adapter并绑定recycleview
        changMianAdapter = new ChangMianAdapter(R.layout.item_changmian);
        rvchangmian.setAdapter(changMianAdapter);
        rvchangmian.setLayoutManager(new LinearLayoutManager(mActivity));

//        initHeadView();//初始化头部布局
        initClub();//初始化集團佈局
    }

    @NonNull
    @Override
    public BasePresenter initPresenter() {
        return ChangMianPresenter.newInstance();
    }


    @Override
    public void initData() {
        super.initData();
        if (fragment.getArguments() != null) {
            loginBean = SpUtils.getObject(MyApplication.app, UsersLoginBean.class);
            queryRegisBean = (QueryRegisBean) fragment.getArguments().getSerializable(Constants.QUERY_SETTING);
            clientindex = fragment.getArguments().getInt(Constants.CLIENTINDEX, 0);
            currency = fragment.getArguments().getString(Constants.CURRENCY_TYPE);
//            ToastUtils.showToast("zhe================"+clientindex);
        }

    }

    /**
     * 下拉刷新監聽
     */
    private void reFreshListener() {
        MaterialHeader header = new MaterialHeader(mContext);
        ptrClass.addPtrUIHandler(header);
        ptrClass.setLastUpdateTimeRelateObject(this);//设置刷新支持时间
        ptrClass.setResistance(1.7f);//设置下拉的阻尼系数，值越大感觉越难下拉
        ptrClass.setDurationToCloseHeader(1000);//设置刷新完成，头部回弹时间，注意和前一个进行区别
        ptrClass.setPullToRefresh(false);//设置下拉过程中执行刷新，我们一般设置为false
        ptrClass.setKeepHeaderWhenRefresh(true);//设置刷新的时候是否保持头部
        ptrClass.setPtrHandler(new PtrDefaultHandler() {               //下拉刷新
            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                //模拟联网，延迟更新数据
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (queryRegisBean != null && !queryRegisBean.getServerSetting().getServerAddress().equals("")) {
                            if (mPresenter != null && ptrClass != null) {
                                isUpdate = true;
                                if (roommonth.equals("全年")) {
                                    //查询明细
                                    showProgressDialog("正在加载...");
                                    mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
                                            clientindex, "", roomyear, chooiseCompany.getText().toString());
                                } else {
                                    //查询明细
                                    showProgressDialog("正在加载...");
                                    mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
                                            clientindex, roommonth, roomyear, chooiseCompany.getText().toString());
                                }
                            } else {
                                hideProgressDialog();
                            }
                            if (ptrClass == null) {
                                hideProgressDialog();
                            }

                        } else {
//                            ToastUtils.showToast("数据异常");
                        }
                    }
                }, 1000);
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        hideProgressDialog();

    }

    /**
     * 时间选择
     */
    private void chooisTime() {
        DialogUIUtils.showDatePick(mActivity, Gravity.CENTER, "选择日期", System.currentTimeMillis() + 60000, DateSelectorWheelView.TYPE_YYYYMM, 0, new DialogUIDateTimeSaveListener() {

            @Override
            public void onSaveSelectedDate(int tag, String selectedDate) {//点击年月监听器
                isCend = true;
                time1 = selectedDate;
                roomyear = selectedDate.substring(0, 4);
                roommonth = selectedDate.substring(selectedDate.length() - 2, selectedDate.length());
//                ToastUtils.showToast(selectedDate+tag);
                time2 = time1.replace("-", "/");
                chooiseTime.setText(time2);
                //查询子户口//查询子户口//查询子户口//查询子户口//查询子户口//查询子户口//查询子户口
                if (roommonth.equals("全年")) {
//                    ToastUtils.showToast("全年");
                    showProgressDialog("正在加载...");
//                    changMianAdapter.removeAllHeaderView();
                    mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
                            clientindex, "", roomyear, chooiseCompany.getText().toString());
//                    LogUtils.e("这是我要的网址"+queryRegisBean.getServerSetting().getServerAddress()+"======="+queryRegisBean.getServerSetting().getServerProject()+"================="+queryRegisBean.getServerSetting().getServerPort());
                } else {
//                    changMianAdapter.removeAllHeaderView();
                    showProgressDialog("正在加载...");
                    mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
                            clientindex, roommonth, roomyear, chooiseCompany.getText().toString());
                }
            }

        }).show();
    }

    /**
     * 场面数据回调
     *
     * @param changmianBean
     */

    @SuppressLint("SetTextI18n")
    @Override
    public void showChangMianDataSuccess(final ChangmianBean changmianBean) {

//        changMianAdapter.removeAllHeaderView();
        //布局处理
        if (changmianBean != null && changmianBean.getClientList() != null && changmianBean.getClientList().size() > 0) {
            ptrClass.setVisibility(View.VISIBLE);
            visible.setVisibility(View.GONE);
        } else {
            visible.setVisibility(View.VISIBLE);
            ptrClass.setVisibility(View.GONE);
        }
        if (changMianAdapter.getData().size() == 0) {
            initRvList(changmianBean);
        } else {
            LogUtil.e("isUpdate==========="+isUpdate);
            if (isUpdate) {
                isUpdate = false;
                changMianAdapter.setNewData(changmianBean.getClientList());
            } else {
                changMianAdapter.addData(changmianBean.getClientList());
            }
        }

        if (changmianBean != null) {
            totalMoney.setText(changmianBean.getCommonValueSum() + getString(R.string.wan));//设置总金额
        }
     if (changmianBean != null){
         totalMoney.setText(changmianBean.getCommonValueSum()+getString(R.string.wan));//设置总金额
     }
        changMianAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {//監聽item 劍點擊
                //获取场面pop数据
                showProgressDialog("正在加载...");
                LogUtil.e("index============"+changmianBean.getClientList().get(position).getWinnumindex());
                mPresenter.changmianpop(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting
                        ().getServerProject(), queryRegisBean.getServerSetting().getServerPort(), changmianBean.getClientList().get(position).getWinnumindex());
            }
        });
        hideProgressDialog();
        ptrClass.refreshComplete();//
    }

    @Override
    public void showNetworkError(Throwable throwable) {
        hideProgressDialog();
        ptrClass.refreshComplete();
    }

    @Override
    public void showqueryAllCurrencyList(final CurrencyListBean currencyListBean) {
        if (currencyListBean.getCurrencys().size() > 0) {
            hideProgressDialog();

//            roomid = Integer.parseInt(allRoomListBean.getRoomList().get(0).getRoomid());
            //填充廳數據
            //初始化一个空list的adapter，网络错误时使用，第一次加载到数据时重新初始化adapter并绑定recycleview
            popAdapter = new PopAdapter(R.layout.pop_list_item, currencyListBean);
            clubrecyclerView.setAdapter(popAdapter);
            clubrecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
            //集團點擊監聽
            popAdapter.setOnCliCkItemListenerr(new PopAdapter.OnCliCkItemListener() {
                @Override
                public void clickItem(int position) {
//                  roomid = Integer.parseInt(currencyListBean.getRoomList().get(position).getRoomid());
                    chooiseCompany.setText(currencyListBean.getCurrencys().get(position).getCurrencyName1());//動態改變集團名稱
                    //查询最大日期
//                    if (position != 0) {
//
//                        showProgressDialog("正在加载...");
////                        mPresenter.queryMaxChangemonth(queryRegisBean.getServerSetting().getServerAddress(),
////                                queryRegisBean.getServerSetting().getServerProject(),
////                                queryRegisBean.getServerSetting().getServerPort(), roomid);
//                    } else {
                        //查询场面
                    isUpdate =true;
                        if (roommonth.equals("全年")) {
                            //查询明细
                            showProgressDialog("正在加载...");
                            LogUtil.e("打印出這個噗街"+clientindex+"======"+roommonth+"========="+roomyear+"=========="+chooiseCompany.getText().toString());
                            mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
                                    clientindex, "", roomyear, chooiseCompany.getText().toString());
                        } else {
                            //查询明细
                            showProgressDialog("正在加载...");
                            LogUtil.e("走了這裡的問題嗎");
                            mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
                                    clientindex, roommonth, roomyear, chooiseCompany.getText().toString());
//                        }
                    }
                    mClubPopWindow.dissmiss();
                }
            });
            mallRoomListBean = currencyListBean;
            //查询场面

            if (roommonth.equals("全年")) {
                //查询明细
                showProgressDialog("正在加载...");
                mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
                        clientindex, "", roomyear, chooiseCompany.getText().toString());
            } else {
                //查询明细
                showProgressDialog("正在加载...");
                LogUtil.e("走了這裡的問題嗎11111");
                mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
                        clientindex, roommonth, roomyear, chooiseCompany.getText().toString());
            }

        } else {
            hideProgressDialog();
        }
    }

//    /**
//     * 查詢廳成功回調
//     *
//     * @param allRoomListBean
//     */
//    @Override
//    public void showqueryAllRoomList(final AllRoomListBean allRoomListBean) {
//        if (allRoomListBean.getRoomList().size() > 0) {
//            roomid = Integer.parseInt(allRoomListBean.getRoomList().get(0).getRoomid());
//            //填充廳數據
//            //初始化一个空list的adapter，网络错误时使用，第一次加载到数据时重新初始化adapter并绑定recycleview
//            popAdapter = new PopAdapter(R.layout.pop_list_item, allRoomListBean.getRoomList());
//            clubrecyclerView.setAdapter(popAdapter);
//            clubrecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
//            //集團點擊監聽
//            popAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
//                @Override
//                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
//                    roomid = Integer.parseInt(allRoomListBean.getRoomList().get(position).getRoomid());
//                    btn_choose_club.setText(allRoomListBean.getRoomList().get(position).getRoomname());//動態改變集團名稱
//                    //查询最大日期
//                    if (position != 0) {
//                        showProgressDialog("正在加载...");
//                        mPresenter.queryMaxChangemonth(queryRegisBean.getServerSetting().getServerAddress(),
//                                queryRegisBean.getServerSetting().getServerProject(),
//                                queryRegisBean.getServerSetting().getServerPort(), roomid);
//                    } else {
//                        //查询场面
//                        if (roommonth.equals("全年")) {
//                            //查询明细
//                            showProgressDialog("正在加载...");
//                            mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
//                                    clientindex, "", roomyear, roomid);
//                        } else {
//                            //查询明细
//                            showProgressDialog("正在加载...");
//                            mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
//                                    clientindex, roommonth, roomyear, roomid);
//                        }
//                    }
//                    mClubPopWindow.dissmiss();
//                }
//            });
//            mallRoomListBean = allRoomListBean;
//            //查询场面
//            if (roommonth.equals("全年")) {
//                //查询明细
//                showProgressDialog("正在加载...");
//                mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
//                        clientindex, "", roomyear, roomid);
//            } else {
//                //查询明细
//                showProgressDialog("正在加载...");
//                mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
//                        clientindex, roommonth, roomyear, roomid);
//            }
//
//        } else {
//            hideProgressDialog();
//        }
//    }

//    /**
//     * 最大日期
//     *
//     * @param maxChangemonthBean
//     */
//    @Override
//    public void showMaxChangemonthList(MaxChangemonthBean maxChangemonthBean) {
//        if (maxChangemonthBean != null) {
//            roomyear = maxChangemonthBean.getRoomyear();
//            roommonth = maxChangemonthBean.getRoommonth();
//            mmaxChangemonthBean = maxChangemonthBean;
//
//            btn_choose_time.setText(maxChangemonthBean.getRoomyear() + "/" + maxChangemonthBean.getRoommonth());//设置日期
//            //查询場面
//            if (queryRegisBean != null && !queryRegisBean.getServerSetting().getServerAddress().equals("")) {
////            changMianAdapter.removeAllHeaderView();
//                if (roommonth.equals("全年")) {
//                    //查询明细
//                    showProgressDialog("正在加载...");
//                    mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
//                            clientindex, "", roomyear, roomid);
//                } else {
//                    //查询明细
//                    showProgressDialog("正在加载...");
//                    mPresenter.queryClientWinnumMessage(queryRegisBean.getServerSetting().getServerAddress(), queryRegisBean.getServerSetting().getServerProject(), queryRegisBean.getServerSetting().getServerPort(),
//                            clientindex, roommonth, roomyear, roomid);
//                }
//            } else {
//                hideProgressDialog();
//            }
//        } else {
//            ToastUtils.showToast("沒有可查詢日期");
//        }
//    }

    /**
     * 场面pop数据回调
     *
     * @param changMianPopBean custom_dialog_changmian
     */
    @Override
    public void showChangMianPopSuccess(ChangMianPopBean changMianPopBean) {

        tv_cash.setText(changMianPopBean.getCash2() + "");
        tv_newM.setText(changMianPopBean.getNewm() + "");
        tv_oldM.setText(changMianPopBean.getWomm() + "");
        tv_wasm.setText(changMianPopBean.getWasm() + "");
        tv_srartsum.setText(StringUtils.FormatNumber(changMianPopBean.getSrartsum() + ""));
        tv_nowset.setText(changMianPopBean.getNowset() + "");
        tv_answerm.setText(changMianPopBean.getAnswerm() + "");
        tv_preserve.setText(changMianPopBean.getPreserve() + "");
        tv_baggo.setText(changMianPopBean.getBaggo() + "");
//        tv_leavesum.setText(StringUtils.FormatNumber(changMianPopBean.getLeavesum() + ""));
        tv_leavesum.setText(changMianPopBean.getLeavesum());

//        ToastUtils.showToast("sssdd===="+changMianPopBean.getWinnumindex());
        hideProgressDialog();
        // 5 在底部显示
        popupWindow.showAtLocation(contentView.findViewById(R.id.rl_custom),
                Gravity.CENTER, 0, 0);

        //变暗
        // 设置背景颜色变暗
        WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
        lp.alpha = 0.5f;
        mActivity.getWindow().setAttributes(lp);
        //弹出view
    }

    @Override
    public void showAllCurrencyNetworkError(Throwable throwable) {
        changMianAdapter.setEmptyView(errorView);
        hideProgressDialog();
        ptrClass.refreshComplete();
    }

//    @Override
//    public void showAllRoomNetworkError(Throwable throwable) {
//        changMianAdapter.setEmptyView(errorView);
//        hideProgressDialog();
//        ptrClass.refreshComplete();
//    }

    /**
     * 填充户口适配器
     *
     * @param changmianBean
     */
    private void initRvList(final ChangmianBean changmianBean) {
        changMianAdapter = new ChangMianAdapter(R.layout.item_changmian, changmianBean);
//        changMianAdapter.addHeaderView(headView);//动态添加头部布局
        rvchangmian.setAdapter(changMianAdapter);
//        reFreshListener();//rv下拉刷新
    }

    /**
     * 弹出窗口
     */
    @SuppressLint("WrongConstant")
    private void inputOtherPwdWindow() {
        contentView = LayoutInflater.from(mActivity).inflate(R.layout.custom_dialog_changmian, null);
        if (popupWindow == null) {
            popupWindow = new PopupWindow(contentView, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
        }

        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                lp.alpha = 1f;
                mActivity.getWindow().setAttributes(lp);
            }
        });
        popupWindow.setTouchable(true);
        popupWindow.setFocusable(true); //设置点击menu以外其他地方以及返回键退出
        popupWindow.setOutsideTouchable(true);   //设置触摸外面时消失
        popupWindow.getContentView().setFocusableInTouchMode(true);
        popupWindow.getContentView().setFocusable(true);
        // 设置弹出窗体的背景
        popupWindow.setBackgroundDrawable(new BitmapDrawable(MyApplication.app.getResources(), (Bitmap) null));
        ColorDrawable cd = new ColorDrawable();
        popupWindow.setBackgroundDrawable(cd);
        //这句话，让pop覆盖在输入法上面
        popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);//设置弹出动画

//        // 5 在底部显示
//        popupWindow.showAtLocation(contentView.findViewById(R.id.rl_custom),
//                Gravity.CENTER, 0, 0);
        tv_cash = contentView.findViewById(R.id.tv_cash);//現金
//        tv_cash.setText(changMianPopBean.getCash2()+"");

        tv_newM = contentView.findViewById(R.id.tv_newM);//新M
//        tv_newM.setText(changMianPopBean.getNewm()+"");

        tv_oldM = contentView.findViewById(R.id.tv_oldM);//旧M
//        tv_oldM.setText(changMianPopBean.getWomm()+"");

        tv_wasm = contentView.findViewById(R.id.tv_wasm);//原M
//        tv_wasm.setText(changMianPopBean.getWasm()+"");

        tv_srartsum = contentView.findViewById(R.id.tv_srartsum);//入场本金
//        ToastUtils.showToast("入场本金="+changMianPopBean.getSrartsum()+"");
//        tv_srartsum.setText(changMianPopBean.getSrartsum()+"");

        tv_nowset = contentView.findViewById(R.id.tv_nowset);//套现
//        tv_nowset.setText(changMianPopBean.getNowset()+"");

        tv_answerm = contentView.findViewById(R.id.tv_answerm);//回M
//        tv_answerm.setText(changMianPopBean.getAnswerm()+"");

        tv_preserve = contentView.findViewById(R.id.tv_preserve);//存
//        tv_preserve.setText(changMianPopBean.getPreserve()+"");

        tv_baggo = contentView.findViewById(R.id.tv_baggo);//袋走
//        tv_baggo.setText(changMianPopBean.getBaggo()+"");

        tv_leavesum = contentView.findViewById(R.id.tv_leavesum);//离场本金
//        tv_leavesum.setText(changMianPopBean.getLeavesum()+"");

    }





    @OnClick({R.id.ibtn_changmian_back, R.id.chooise_company, R.id.chooise_time})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ibtn_changmian_back:
                pop();
                break;
            case R.id.chooise_company:
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    mClubPopWindow.showAsDropDown(chooiseCompany, 0, 0, Gravity.CENTER);
                    // 设置背景颜色变暗
                    WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                    lp.alpha = 0.5f;
                    mActivity.getWindow().setAttributes(lp);
                } else {
                    mClubPopWindow.showAsDropDown(chooiseCompany, 0, 0);
                    // 设置背景颜色变暗
                    WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                    lp.alpha = 0.5f;
                    mActivity.getWindow().setAttributes(lp);
                }
                break;
            case R.id.chooise_time:
                chooisTime();
                break;
        }
    }
}
